<template>
  <div class="all" ref="box">
    <header>
      <div class="div" @click="back">
        <img src="../../assets/返回.png" alt="">
        <span class="solid">返回</span>
      </div>
      <div class="div">
        <span>我的服务团队</span>
<!--        <ul class="menu">-->
<!--          <li :class="menuIndex == 0 ? 'selectMenu' : ''" @click="menuIndex = 0">医生</li>-->
<!--          <li :class="menuIndex == 1 ? 'selectMenu' : ''" @click="menuIndex = 1,getTeamList(),page=1">团队</li>-->
<!--        </ul>-->
      </div>
      <div class="div">
        <span></span>
      </div>
    </header>
    <div class="box"
         v-show="menuIndex == 0"
         @click="clickBox(item)"
         v-for="(item, index) in doctorList" :key="index">
      <div class="box_left">
        <img v-if="item.PHOTO !== '' && item.PHOTO !== undefined && item.PHOTO !== null" :src="item.PHOTO" class="PHOTO" alt="">
        <img v-else src="../../assets/男医生@2x.png" class="PHOTO" alt="">
      </div>
      <div class="box_right">
        <ul>
          <li>
            <span class="name">
              <span style="font-weight: bold;font-size: 15px">{{item.NICK_NAME}}</span>
              <span>|</span>
              <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>
              <span>|</span>
              <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>
            </span>
          </li>
          <li>
            <span class="jieShao">{{item.HOSPITAL_NAME}}</span>
            <button class="biaoqian" v-if="item.GRADE">{{item.GRADE}}</button>
          </li>
        </ul>
        <div class="box_rigth_bottom">
          <p>
            <a >接诊率:</a><span>{{item.jiezhenCount}}</span>
            <a >好评率:</a><span>{{item.haopingLv}}</span>
            <a >咨询量:</a><span>{{item.zixunCount}}</span>
          </p>
          <p class="goodAt">
            <a style="display: block">擅长:</a>
            <span>{{item.Goodat}}</span>
          </p>
          <p>
            <a >最快回复:</a>
            <span style="color: #1DA4F2"  v-if="item.min !== undefined && item.min !== null && item.min !== ''">{{item.min}}</span>
            <span v-else style="color: #999999">暂无</span>
            <a >平均回复:</a>
            <span style="color: #1DA4F2" v-if="item.avg !== undefined && item.avg !== null && item.avg !== ''">{{item.avg}}</span>
            <span style="color: #999999" v-else>暂无</span>
          </p>
        </div>
      </div>
    </div>

    <div class="box"
         v-show="menuIndex == 1"
         @click="clickBox(item)"
         v-for="(item, index) in teamList" :key="index">
      <div class="box_left">
        <img v-if="item.team_icon !== '' && item.team_icon !== undefined && item.team_icon !== null"
             :src="item.team_icon" class="PHOTO" alt="">
        <img v-else src="../../assets/男医生@2x.png" class="PHOTO" alt="">
      </div>
      <div class="box_right">
        <ul>
          <li>
            <span class="name">
              {{item.team_name}}
              <a style="font-size: 13px;font-weight: 500">（{{item.count}}人）</a>
<!--              ({{item.count}}人)-->
            </span>
            <button v-show="topActive == 1" class="btnXiangQing" @click.stop="quitTeam(item)">
              退出团队
            </button>
            <button v-show="topActive == 2 && Number(item.shenqing) != 1" class="btnXiangQing" @click.stop="insertTeam(item)">
              加入团队
            </button>
            <span v-show="Number(item.shenqing) === 1" style="color: #1da4f2">申请中</span>
          </li>
          <li>
            <span>团队长：{{item.NICK_NAME}}</span>
            &nbsp;
            &nbsp;
<!--            <span>团队人数：{{item.count}}人</span>-->
            <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>
            <span>|</span>
            <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>
          </li>
<!--          <li>-->
<!--            <span style="font-weight: 500;font-size: 13px !important;">{{item.MAJOR}}</span>-->
<!--            <span>|</span>-->
<!--            <span style="font-weight: 500;font-size: 13px !important;">{{item.DEPART}}</span>-->
<!--          </li>-->
          <li>
            <span class="jieShao">{{item.HOSPITAL_NAME}}</span>
            <button class="biaoqian">{{item.GRADE}}</button>
          </li>
        </ul>
<!--        <div class="box_rigth_bottom">-->
<!--          <p>-->
<!--            <a >接诊率:</a>-->
<!--            <span v-if=" item.jiezhenCount!== undefined && item.jiezhenCount!== null && item.jiezhenCount!== ''">{{item.jiezhenCount}}</span>-->
<!--            <span v-else>暂无</span>-->
<!--            <a >好评率:</a>-->
<!--            <span v-if=" item.haopingLv!== undefined && item.haopingLv!== null && item.haopingLv!== ''">{{item.haopingLv}}</span>-->
<!--            <span v-else>暂无</span>-->
<!--            <a >咨询量:</a>-->
<!--            <span v-if=" item.zixunCount!== undefined && item.zixunCount!== null && item.zixunCount!== ''">{{item.zixunCount}}</span>-->
<!--            <span v-else>暂无</span>-->
<!--          </p>-->
<!--          <p class="goodAt">-->
<!--            <a style="display: block">擅长:</a>-->
<!--            <span>{{item.team_goodat}}</span>-->
<!--          </p>-->
<!--          <p>-->
<!--            <a >最快回复:</a>-->
<!--            <span style="color: #1DA4F2"  v-if="item.min !== undefined && item.min !== null && item.min !== ''">{{item.min}}</span>-->
<!--            <span v-else style="color: #999999">暂无</span>-->
<!--            <a >平均回复:</a>-->
<!--            <span style="color: #1DA4F2" v-if="item.avg !== undefined && item.avg !== null && item.avg !== ''">{{item.avg}}</span>-->
<!--            <span style="color: #999999" v-else>暂无</span>-->
<!--          </p>-->
<!--          <p class="goodAt" style="margin-top: 10px" v-show="item.manager_doc_name">-->
<!--            <a >责任医生:</a>-->
<!--            <span style="color: #1da5f2!important;">{{item.manager_doc_name}}</span>-->
<!--          </p>-->
<!--        </div>-->
      </div>
    </div>

    <van-loading v-show="isLoading" size="24px" style="width: 100%;height: 80%;
    display:flex;align-items:center;justify-content:center; color: #1da4f2" vertical>
      加载中...
    </van-loading>
    <van-empty
      style="width: 100%;height: 60%"
      v-show="((menuIndex == 0 && doctorList.length <= 0) || (menuIndex == 1 && teamList.length <= 0)) && isLoading === false"
      class="custom-image"
      :image="require('../../assets/空两本书.png')"
      :description=" `暂无`+typeText"
    />
  </div>
</template>

<script>
export default {
  name: 'ManageDoctorOrTeam',
  data () {
    return {
      page: 1,
      menuIndex: 1,
      doctorList: [],
      teamList: [],
      userid: this.$route.query.userid,
      isScroll: true,
      isLoading: true
    }
  },
  computed: {
    typeText () {
      if (this.menuIndex == 0) {
        return '医生'
      } else if (this.menuIndex == 1) {
        return '团队'
      }
    }
  },
  mounted () {
    if (this.menuIndex == 0) {
      this.getDoctorList()
    } else if (this.menuIndex == 1) {
      this.getTeamList()
    }
    window.addEventListener('scroll', this.scrollBottom, true)
  },
  methods: {
    // 滚动事件
    scrollBottom () {
      let scrollTop = this.$refs.box.scrollTop
      let clientHeight = this.$refs.box.clientHeight
      let scrollHeight = this.$refs.box.scrollHeight
      if (scrollHeight - scrollTop <= clientHeight + 300 && this.isScroll === true && this.teamActive == 1) {
        this.isScroll = false
        setTimeout(() => {
          this.page += 1
          this.isLoading = true
          // 移除滚动事件
          window.removeEventListener('scroll', this.scrollBottom, true)
          this.getTeamList()
        }, 500)
      }
    },
    clickBox (item) {
      // 移除滚动事件
      window.removeEventListener('scroll', this.scrollBottom, true)
      if (this.menuIndex == 0) {
        this.$router.push({path: '/doctorInfo', query: {doc_user_id: item.USER_ID}})
      } else if (this.menuIndex == 1) {
        this.$router.push({path: '/PatientsLookTeam',
          query: {
            id: item.id,
            team_id: item.id,
            userid: this.userid
          }})
      }
    },
    getDoctorList () {
      this.isLoading = true
      this.$http.findDoctor({is_manage: 1})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.doctorList = res.data.data
            this.isLoading = false
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    getTeamList () {
      this.isLoading = true
      this.$http.TeamList({
        page: this.page,
        is_manage: 1
      })
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            // this.teamList = res.data.data
            var _this = this
            if (Number(this.page) === 1) {
              this.teamList = []
              this.teamList = res.data.data
            } else {
              res.data.data.forEach(function (current, index, arr) {
                _this.teamList.push(current)
              })
            }
            if (res.data.data.length > 0) {
              window.addEventListener('scroll', this.scrollBottom, true)
              this.isScroll = true
            } else {
              window.removeEventListener('scroll', this.scrollBottom, true)
              this.isScroll = false
            }
            this.isLoading = false
          } else {
            this.$toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          this.$toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  },
  destroyed () {
    // 移除滚动事件
    window.removeEventListener('scroll', this.scrollBottom, true)
  }
}
</script>

<style scoped>
.all{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  position: sticky;
  top: 0;
  z-index: 9;
}
.div{
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div img{
  margin-right: 5px;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-left: 15px;
}
.div:nth-child(3) img{
  margin-right: 5px;
  width: 13px;
  height: 13px;
}
.div:nth-child(3) span{
  margin-right: 15px;
}
.div:nth-child(1) {
  flex: 1;
}
.div:nth-child(2){
  flex: 2;
  justify-content: center;
}
.div:nth-child(3){
  flex: 1;
  justify-content: flex-end;
}
.solid{
  color: #1DA4F2;
}
.menu{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
}
.menu li {
  width: 90px;
  height: 29px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1da5f2;
  margin-left: -2px;
  background: #FFFFFF;
}
.menu li:first-child{
  border-radius: 5px 0 0 5px;
}
.menu li:last-child{
  border-radius: 0 5px 5px 0;
}
.selectMenu{
  background: #1da5f2 !important;
  color: #FFFFFF !important;
}

.box{
  padding: 10px;
  box-sizing: border-box;
  background: white;
  margin-bottom: 8px;
  display: flex;
}
.all .box:last-of-type{
  margin-bottom: 60px;
}
.PHOTO{
  width: 55px;
  height: 55px;
  border-radius: 50%;
  object-fit: cover;
}
.box_left{
  width: 23%;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: space-between;
}
.dict_name{
  font-size: 11px;
  border: 1px solid #1DA4F2;
  border-radius: 2px;
  background: rgba(16, 184, 246, 0.1);
  color: #1da4f2;
  padding: 1px 3px;
  box-sizing: border-box;
  white-space: nowrap;
  /*margin-top: 10px;*/
}
.box_right{
  width: 78%;
}
.box_right ul{
  /*height: 60px;*/
  display: flex;
  flex-direction: column;
  align-content: space-around;
  justify-content: space-around;
}
.box_right ul li{
  display: flex;
  align-items: center;
  font-size: 13px;
  font-family: PingFang SC;
  min-height: 30px;
}
.box_right ul li:nth-child(1){
  justify-content: space-between;
}
.name{
  font-size: 15px!important;
  font-weight: bold;
  color: #333333;
}
.biaoqian{
  /*padding: 0px 8px;*/
  min-width: 44px;
  height: 18px;
  border-radius: 15px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  /* background: rgba(29, 164, 242, 0.1); */
  background: transparent;
  color: #1DA4F2;
  /* border: none; */
  border: 1px solid;
  font-size: 11px;
  margin-left: 8px;
}
.btnXiangQing{
  color: white;
  background: #1DA4F2;
  border: none;
  padding: 3px 8px;
  border-radius: 2px;
  box-sizing: border-box;
  font-size: 11px;
}
.btnXiangQing img{
  width: 5px;
  height: 9px;
  margin-left: 5px;
}

.btnXiangQing,
.biaoqian,
.jieShao
{
  display: flex;
  align-items: center;
  justify-content: center;
}
.jieShao{
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
  margin-right: 8px;
}
.box_rigth_bottom{
  margin-top: 5px;
}
.box_rigth_bottom p{
  margin-bottom: 5px;
}
.box_rigth_bottom p:nth-child(1),
.box_rigth_bottom p:nth-child(3){
  font-size: 13px;
}
.box_rigth_bottom p a{
}
.box_rigth_bottom p span{
  color: #E3170D;
  margin: 0 8px 0 3px;
}
.goodAt{
  font-size: 13px;
  display: flex;
}
.goodAt a{
  display: block;
  white-space: nowrap;
}
.goodAt span{
  /*width: 80%;*/
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #333 !important;
}
</style>
